#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>

using ll = int64_t;

static inline void solve() {
    int n;
    std::cin >> n;
    std::string s1, s2, t1, t2;
    std::cin >> s1 >> s2 >> t1 >> t2;

    ll ans = 0;
    std::vector<bool> p(n, false); 
    for (int i = 0; i < n; ++i) {
        if (t1[i] == '0' && t2[i] == '0') {
            if (s1[i] == s2[i]) {
                ans++;
            }
            p[i] = true; 
        }
    }
    int idx = 0;
    while (idx < n) {
        while (idx < n && (p[idx] || t1[idx] == '0' || t2[idx] == '0')) {
            idx++;
        }
        if (idx >= n) {
            break;
        }
        int s = idx;
        int e = s;
        while (e + 1 < n && !p[e + 1] && t1[e + 1] == '1' && t2[e + 1] == '1') {
            e++;
        }
        int s10 = 0, s11 = 0;
        int s20 = 0, s21 = 0;
        for (int i = s; i <= e; ++i) {
            if (s1[i] == '0') s10++;
            else s11++;
            
            if (s2[i] == '0') s20++;
            else s21++;
        }
        ans += std::min(s10, s20) + std::min(s11, s21);
        idx = e + 1;
    }
    std::cout << ans << "\n";
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int T;
    std::cin >> T;
    while (T--) {
        solve();
    }
}
